package com.zj.leetcode.medium.greed;

/**
 * @program: algorithm
 * @description:
 * 买卖股票的最佳时机 II
 * 122 best-time-to-buy-and-sell-stock-ii
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class BestTimeToBuyAndSellStockIi{
    public static void main(String[] args) {
        Solution solution = new BestTimeToBuyAndSellStockIi().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int maxProfit(int[] prices) {
            if(prices.length <= 1){
                return 0;
            }

            int profit = 0;
            for (int i = 1; i < prices.length; i++) {
                int sub = prices[i] - prices[i - 1];
                if(sub > 0){
                    profit+=sub;
                }
            }
            return profit;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
